package com.tianji.learning.service.impl;

import com.tianji.common.utils.BeanUtils;
import com.tianji.common.utils.ObjectUtils;
import com.tianji.common.utils.UserContext;
import com.tianji.learning.domain.dto.ReplyDTO;
import com.tianji.learning.domain.po.InteractionReply;
import com.tianji.learning.mapper.InteractionReplyMapper;
import com.tianji.learning.service.IInteractionQuestionService;
import com.tianji.learning.service.IInteractionReplyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 互动问题的回答或评论 服务实现类
 * </p>
 * @author 陈彦祖
 * @since 2024-11-12
 */
@Service
@RequiredArgsConstructor
public class InteractionReplyServiceImpl extends ServiceImpl<InteractionReplyMapper, InteractionReply> implements IInteractionReplyService {

    private final IInteractionQuestionService questionService;

    /**1
     * 新增回答或评论
     * @param replyDTO
     */
    @Override
    public void addReplies(ReplyDTO replyDTO) {
        //1，获取当前登录人
        Long userId = UserContext.getUser();
        //2，新增回答或评论
        InteractionReply reply = BeanUtils.toBean(replyDTO, InteractionReply.class);
        //2.1，设置用户id
        reply.setUserId(userId);
        save(reply);
        //累加回答数
        boolean addAnswer = replyDTO.getAnswerId() == null;
        //判断回复类型：回答问题、回复评论、回复评论的评论
        if (ObjectUtils.isNotEmpty(replyDTO.getTargetReplyId())){
            questionService.lambdaUpdate();

        }

        //是评论回复，则累加评论数
    }
}
